package jsyf.oa.web.wechat.service_account.controller;

import com.alibaba.fastjson.JSONObject;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.wechat.service_account.WechatCustomServiceFacade;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping(value = "/customService")
public class CustomServiceController {

    @Resource
    private WechatCustomServiceFacade wechatCustomServiceFacade;
    /**
     * 服务号-发送客服消息
     */
    @RequestMapping(value = "/sendMessage.json", method = RequestMethod.POST)
    public void sendMessage(HttpServletResponse response, @RequestBody String jsonData) {

        JSONObject jsonObject = wechatCustomServiceFacade.sendMessage(jsonData);
        if (jsonObject != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(jsonObject));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }
    /**
     * 服务号-添加客服账号
     */
    @RequestMapping(value = "/addCustomservice.json", method = RequestMethod.POST)
    public void addCustomservice(HttpServletResponse response, @RequestBody String jsonData) {

        JSONObject jsonObject = wechatCustomServiceFacade.addCustomservice("{\n" +
                "     \"kf_account\" : \"18636872320\",\n" +
                "     \"nickname\" : \"客服-赵鹏\",\n" +
                "     \"password\" : \"965eb72c92a549dd\",\n" +
                "}");
        if (jsonObject != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(jsonObject));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }

    /**
     * 服务号-获取客服账号
     */
    @RequestMapping(value = "/getCustomservice.json", method = RequestMethod.POST)
    public void getCustomservice(HttpServletResponse response, @RequestBody String jsonData) {

        JSONObject jsonObject = wechatCustomServiceFacade.getCustomservice();
        if (jsonObject != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(jsonObject));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }
}
